package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FeedFormMain;
import com.ruoyi.system.service.IFeedFormMainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * FeedFormMainController
 */
@Anonymous
@RestController
@RequestMapping("/system/main")
public class FeedFormMainController extends BaseController
{
    @Autowired
    private IFeedFormMainService feedFormMainService;

    /**
     * 查询投喂单配置列表
     */
    //@PreAuthorize("@ss.hasPermi('system:main:list')")
    @GetMapping("/list")
    public TableDataInfo list(FeedFormMain feedFormMain)
    {
        startPage();
        List<FeedFormMain> list = feedFormMainService.selectFeedFormMainList(feedFormMain);
        return getDataTable(list);
    }

    /**
     * 导出投喂单配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:main:export')")
    @Log(title = "投喂单配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FeedFormMain feedFormMain)
    {
        List<FeedFormMain> list = feedFormMainService.selectFeedFormMainList(feedFormMain);
        ExcelUtil<FeedFormMain> util = new ExcelUtil<FeedFormMain>(FeedFormMain.class);
        util.exportExcel(response, list, "投喂单配置数据");
    }

    /**
     * 获取投喂单配置详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:main:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(feedFormMainService.selectFeedFormMainById(id));
    }

    /**
     * 新增投喂单配置
     */
    //@PreAuthorize("@ss.hasPermi('system:main:add')")
    @Log(title = "投喂单配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeedFormMain feedFormMain)
    {
        return toAjax(feedFormMainService.insertFeedFormMain(feedFormMain));
    }

    /**
     * 修改投喂单配置
     */
    //@PreAuthorize("@ss.hasPermi('system:main:edit')")
    @Log(title = "投喂单配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeedFormMain feedFormMain)
    {
        return toAjax(feedFormMainService.updateFeedFormMain(feedFormMain));
    }

    /**
     * 删除投喂单配置
     */
    //@PreAuthorize("@ss.hasPermi('system:main:remove')")
    @Log(title = "投喂单配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(feedFormMainService.deleteFeedFormMainByIds(ids));
    }
}
